/*
 *  SFClib Tester - Secure File Container Library Test Utility
 *
 *  sfclib_unittest.cpp - Copyright(c) 2009 The SFCLib authors
 *
 *  The original author of this file is: Roberto Estrada Casarrubios.
 *
 *	This file is part of SFClib Tester.
 *
 *  SFClib Tester is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  SFClib Tester is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with SFClib Tester.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "sfclib.h"
#include <gtest/gtest.h>

/**
 * Tests the creation of a new SFC File
 */
TEST(SFCCreationSuccesful,CreateSFCFileTest)
{
	EXPECT_EQ(0,createSFC("testsfc.sfc","thisisatestkey"));
}

/**
 * Tests if a file is created correctly in the filesystem
 */
TEST(FileCreation,CreateANewFile)
{
	EXPECT_EQ(1,sf_creat("TestCaseFile.tmp"));
}

/**
 * Tests if a name which can overflow an entry is discarded
 */
TEST(FileCreation,NameOverFlowHandling)
{
	EXPECT_EQ(-1,sf_creat("218K37TWU#EE075EI37#EA475D496#J617N9890#3187E77OZ#9U1LA4E4D#5F4PD3931#AH4Y6DS24#Q536G29U3#F4689I92P#5V4KP7CB5#6070Z0251#65PSRXMA2#97CF8EWBN#692864GI0#4X26TO115#5980039AP#83F8F6905#HVFD04U42#RE34JSG7H#94548O53Q#IOK49954T#6I44916CS#7B67Y3008#H97HF6RT0#1873OF.overflow"));
}

/**
 * Tests if the file list is grown adequately
 */
TEST(FileCreation,ReallocTest)
{
	EXPECT_EQ(2,sf_creat("TestCaseFile2.tmp"));
}

/**
 * Tests the safety check to avoid two files
 * with the same name in the same directory
 */
TEST(FileCreation,FileWithSameNameTest)
{
	EXPECT_EQ(-1,sf_creat("TestCaseFile.tmp"));
}

/**
 * End of usage of the library, this test
 * checks if the library ends successfully
 */
TEST(LibraryDestruction,SFCLibEndOfUsageTest)
{
	EXPECT_EQ(0,libdestroy());
}